﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SimTank
{
    public partial class DeathKnight : BaseMob
    {
        Rune Blood;
        Rune Unholy;
        Rune Frost;

        public DeathKnight(int uid)
            : base(uid)
        {
            Blood = new Rune();
            Unholy = new Rune();
            Frost = new Rune();
        }

        private int runicpower = 0;
        protected int RunicPower
        {
            get
            {
                return runicpower;
            }
            set
            {
                if (value > 100)
                    runicpower = 100;
                else
                    runicpower = value;
            }
        }

        protected int diseasesOnTarget(BaseMob target)
        {
            return target.DebuffList.FindAll(delegate(Debuff d)
            {
                return d.dispeltype == DispelType.Disease;
            }).Count;
        }

        public override TargettedAttack Action()
        {
            TargettedAttack ret = new TargettedAttack();
            swingremaining--;  //reduce the swing timer by the elapsed interval
            GCD--;
            if (GCD.cool_remain < 0)
            {
                for (int i = 0; i < Priority.Count; i++)
                {
                    if (SpellResourcesAvailable(Priority[i].SpellID))
                    {
                        if (CheckSpellConditionals(Priority[i]))
                        {
                            ret.attack.Add(CastSpell(Priority[i]));
                            GCD.Activate();
                            break;
                        }
                    }
                }
                    
            }
            if (swingremaining <= 0)  //make a swing
            {
                //calculate the size of the hit and if it is a critical hit
                int hit_size = random.Next(damage_min, damage_max);
                swingremaining = swinglength;
                attacks++;
                ret.attack.Add(new Attack("Melee", hit_size, SchoolEnum.Physical));
            }
            ret.targetuid = target;
            ret.sourceuid = unitid;
            return ret;
        }

        private Attack CastSpell(attackQueueObject attackQueueObject)
        {
            if (attackQueueObject.SpellID == 45477)
            {
                return IcyTouch;
            }
            if (attackQueueObject.SpellID == 45462) // Plague Strike
            {
                return PlagueStrike;
            }
            if (attackQueueObject.SpellID == 48721) // Blood Boil
            {
                return BloodBoil;
            }
            if (attackQueueObject.SpellID == 56815) // Rune Strike
            {
                return RuneStrike;
            }
            if (attackQueueObject.SpellID == 55050) //Heart Strike
            {
                return HeartStrike;
            }
            if (attackQueueObject.SpellID == 77513) // Death Strike
            {
                return DeathStrike;
            }
            if (attackQueueObject.SpellID == 49028 && RunicPower > 60) // DRW
            {
                //needs to be DRW
            }
            return new Attack();
        }

        bool SpellResourcesAvailable(int SpellID)
        {
            if (SpellID == 45477 && Frost.Available())
                return true;
            else if (SpellID == 45462 && Unholy.Available())
                return true;
            else if (SpellID == 48721 && Blood.Available())
                return true;
            else if (SpellID == 56815 && RunicPower >= 30)
                return true;
            else if (SpellID == 55050 && Blood.Available())
                return true;
            else if (SpellID == 77513 && (Frost.Available() && Unholy.Available()))
                return true;
            else if (SpellID == 49028 && RunicPower > 60)
                return true;
            return false;
        }

        public override void ReturnResult(int SpellID, int result)
        {
            if (SpellID == 45462 && (result == 2 || result == 3))
                    Unholy.Refund();
            else if (SpellID == 55050 && (result == 2 || result == 3))
                    Blood.Refund();
            else if (SpellID == 77513)
            {
                if (result == 2 || result == 3)
                {
                    Frost.Refund();
                    Unholy.Refund();
                }
                else if (result == 4 || result == 5 || result == 6)
                {
                    DeathStrikeHeal();
                }
            }
        }

        private void DeathStrikeHeal()
        {
            
        }
    }
}

